Skip to content

Add UKP problem instances from vOptLib #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 16, 2025
Merged

Add UKP problem instances from vOptLib #115

merged 2 commits into from
Jun 16, 2025

Conversation

odow
Copy link
Member

@odow odow commented Jun 12, 2025

x-ref #113

module UKP

using JuMP
import JSON

const ROOT = joinpath(@__DIR__, "UKP")

function get_next_line(io)
    while !eof(io)
        line = readline(io)
        if isempty(line) || startswith(line, "#")
            continue
        end
        return line
    end
    return nothing
end

function build_model(filename)
    C, w, W = open(filename, "r") do io
        N = parse(Int, get_next_line(io))
        P = parse(Int, get_next_line(io))
        K = parse(Int, get_next_line(io))
        @assert K == 1
        C = zeros(P, N)
        for p in 1:P
            for i in 1:N
                C[p, i] = parse(Float64, get_next_line(io))
            end
        end
        w = zeros(N)
        for i in 1:N
            w[i] = parse(Float64, get_next_line(io))
        end
        W = parse(Float64, get_next_line(io))
        return (C, w, W)
    end
    P, N = size(C)
    model = Model()
    @variable(model, x[1:N], Bin)
    @constraint(model, w' * x <= W)
    @objective(model, Max, C * x)
    return model
end

function main()
    instances = ["2KP50-11", "2KP50-50", "2KP50-92", "2KP100-50"]
    for instance in instances
        dat_filename = joinpath(ROOT, "instances", "1A", instance * ".dat")
        model = build_model(dat_filename)
        write_to_file(model, joinpath("instances/models", instance * ".mof.json"))
        x_filename = joinpath(ROOT, "X", instance * ".max")
        solutions = Dict{String,Any}[]
        open(x_filename, "r") do io
            for line in readlines(io)
                items = split(line)
                X = ifelse.(codeunits(items[end]) .== UInt8('1'), 1, 0)
                Y = parse.(Float64, items[1:end-1])
                push!(solutions, Dict("X" => X, "Y" => Y))
            end
        end
        solution_filename = joinpath("instances/solutions", instance * ".json")
        write(solution_filename, JSON.json(solutions))
    end
    return
end

end  # module UKP

UKP.main()

@odow odow changed the title WIP: add some problems from vOptLib Add UKP problem instances from vOptLib Jun 16, 2025
Copy link

codecov bot commented Jun 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.85%. Comparing base (04fdfeb) to head (1d9ffc5).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #115   +/-   ##
=======================================
  Coverage   98.85%   98.85%           
=======================================
  Files           9        9           
  Lines         959      959           
=======================================
  Hits          948      948           
  Misses         11       11           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@odow odow merged commit 10120b5 into master Jun 16, 2025
7 checks passed
@odow odow deleted the od/vOptLib branch June 16, 2025 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant